package com.veo.dao;

import com.veo.domain.Product;
import org.apache.ibatis.annotations.*;


import java.util.List;

public interface ProductDao {

    //查询所有的产品(动态查询)
//    @Select("select * from product")
    @Select("<script>" + "select * from product "+"<where>"+
            "<if test=\"searcherName!= null and searcherName!=''\"> productName like concat(#{searcherName},'%')</if>"+
            "</where>"+
            "</script>")
    List<Product> findAllProduct(@Param("searcherName") String searcherName);

    //插入新的产品
    @Insert("insert into product(id,productNum,productName,DepartureTime,cityName,productPrice,productStatus,productDesc) " + "values(#{id},#{productNum},#{productName},#{departureTime},#{cityName},#{productPrice},#{productStatus},#{productDesc})")
    int addProduct(Product product);

    //根据id查询产品
    @Select("select * from product where id=#{id}")
    Product findProductById(String id);

    //修改产品
    @Update("update product set productNum=#{productNum},DepartureTime=#{departureTime},cityName=#{cityName},productPrice=#{productPrice},productStatus=#{productStatus},productDesc=#{productDesc} where id=#{id}")
    int updateProduct(Product product);

    //删除产品
    @Delete("delete from product where id=#{id}")
    int deleteProductById(String id);

    //修改产品的状态
    @Update("update product set productStatus=#{status} where id=#{id}")
    int updateProductStatus(@Param(value = "id") String id, @Param(value = "status") Integer status);
}
